{% extends base %}

{% block body_left %}

{% include common/script/load_select2.html %}
{% include system/component/system_css.html %}

<!-- TODO d3.js 展示内存和CPU日志 -->
{% import web %}

<div class="card">
    <div class="card-title btn-line-height">
        <span>{{html_title}}</span>
        <div class="float-right">
            {% if show_admin_btn %}
                <a class="btn btn-default" href="{{_server_home}}/system/admin">后台管理</a>
            {% end %}

            {% if show_back_btn %}
                {% include common/button/back_button.html %}
            {% end %}
        </div>
    </div>
</div>

{% include settings/page/settings_tab.html %}

<div class="col-md-12 card">

    {% if category == "search" %}

        {% include settings/page/settings_search.html %}

    {% elif category == "admin" %}

        {% include settings/page/settings_admin.html %}

    {% else %}

        {% include settings/page/settings_note.html %}

    {% end %}
</div>

<script type="text/javascript">
    function updateSetting(key, value, type, p) {
        xnote.http.post("/system/config", 
            {key: key, value: value, type: type, p:p}, 
            function (data) {
                if (data.success) {
                    window.location.reload();
                } else {
                    xnote.alert(data.message);
                }
        }).fail(function (resp) {
            console.log(resp);
            xnote.alert(resp.message);
        });
    }

    $("[type=radio]").on("change", function (e) {
        var val = $(e.target).val();
        var key = $(e.target).attr("name");
        var type = $(this).attr("data-type");
        var p = $(this).attr("data-p");
        // alert(val);
        updateSetting(key, val, type, p);
    });

    $("select").change(function (e) {
        var key = $(this).attr("name");
        var val = $(this).val();
        var type = $(this).attr("data-type");
        var p = $(this).attr("data-p");
        updateSetting(key, val, type, p);
    });
</script>

{% end %}

{% block body_right %}
    {% include settings/page/settings_sidebar.html %}
{% end %}